<template>
    <div class="cancelAccouunt topStyley">
        <!--销户页面 -->
        <el-card class="box-card">
            <div slot="headerss" class="clearfix text_fl">
                <span>销户申请</span>
                <el-button class="btn_close" type="text" @click="handleClose">关闭</el-button>
            </div>
            <div>
                <div v-show="step1Page">
                    <el-form
                        ref="formData"
                        :model="formData"
                        :inline="true"
                        :rules="rules"
                        label-width="150px"
                        class="formData_form_inline"
                    >
                        <el-row>
                            <el-col :span="11" :offset="1">
                                <el-form-item label="账户类别:" class="text_fl">
                                    <el-select
                                        v-model="searchForm.accttype"
                                        placeholder="请选择账户类别"
                                        @change="changeCardList"
                                        disabled
                                    >
                                        <el-option
                                            v-for="item in AccountionTYPE_INFO"
                                            :label="item.label"
                                            :key="item.label"
                                            :value="item.code"
                                        ></el-option>
                                    </el-select>
                                </el-form-item>
                            </el-col>
                            <el-col :span="11">
                                <el-form-item label="卡号:" class="text_fl">
                                    <el-select
                                        v-model="searchForm.cardno"
                                        placeholder="请选择卡号"
                                        disabled
                                    >
                                        <el-option
                                            v-for="item in cardList"
                                            :label="item.CARDNBR"
                                            :value="item.CARDNBR"
                                            :key="item.CARDNBR"
                                        ></el-option>
                                    </el-select>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="11" :offset="1">
                                <el-form-item label="当前账面余额：" class="text_fl">
                                    <span
                                        class="el-form-item-span"
                                    >{{pageFormValue.bookBalanceflag }}{{pageFormValue.bookBalance }}</span>
                                    <span
                                        style="color:red;margin-left:5px;"
                                    >{{pageFormValue.ifbalancepass!='0'?'':'不通过' }}</span>
                                </el-form-item>
                            </el-col>

                            <el-col :span="11">
                                <el-form-item label="授权未请款金额：" class="text_fl">
                                    <span class="el-form-item-span">{{pageFormValue.authNoClaim }}</span>
                                    <span
                                        style="color:red;margin-left:5px;"
                                    >{{pageFormValue.authNoClaim!=0?'不通过':'' }}</span>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="11" :offset="1">
                                <el-form-item label="应收未收违约金：" class="text_fl">
                                    <span
                                        class="el-form-item-span"
                                    >{{pageFormValue.uncollectedPenalty }}</span>
                                    <span
                                        style="color:red;margin-left:5px;"
                                    >{{pageFormValue.uncollectedPenalty!=0?'不通过':'' }}</span>
                                </el-form-item>
                            </el-col>
                            <el-col :span="11">
                                <el-form-item label="是否有未结清分期：" class="text_fl">
                                    <span
                                        class="el-form-item-span"
                                    >{{pageFormValue.isHaveInstallment==='1'?'是':'否' }}</span>
                                    <span
                                        style="color:red;margin-left:5px;"
                                    >{{pageFormValue.isHaveInstallment==='1'?'不通过':'' }}</span>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="11" :offset="1">
                                <el-form-item label="是否为制卡日：" class="text_fl">
                                    <span
                                        class="el-form-item-span"
                                    >{{pageFormValue.isMakeCardDay==='1'?'是':'否' }}</span>
                                    <span
                                        style="color:red;margin-left:5px;"
                                    >{{pageFormValue.isMakeCardDay==='1'?'不通过':'' }}</span>
                                </el-form-item>
                            </el-col>
                            <el-col :span="11"></el-col>
                        </el-row>
                        <!-- <el-row v-show="ifauditpass">
                            <el-col :span="24">
                                <el-form-item label="初审不通过原因：" class="text_fl" :span="24">
                                    <span
                                        :span="24"
                                        style="color:red;"
                                    >{{pageFormValue.unpassreason }}</span>
                                </el-form-item>
                            </el-col>
                        </el-row>-->
                        <div class="text_center" style="margin-bottom:20px;">
                            <el-button type="primary" size="small" @click="step1Submit">销户初审</el-button>
                        </div>
                    </el-form>
                </div>
                <div v-show="step2Page">
                    <div class="cardY">
                        <div class="tab-header">
                            <div class="bodyTitles">销户原因</div>
                        </div>
                        <el-row>
                            <el-checkbox-group
                                name="closeReasonList"
                                v-model="formData.closeReason"
                            >
                                <el-col :span="6" v-for="item in closeReasonList" :key="item.label">
                                    <el-checkbox
                                        :label="item.label"
                                        :key="item.code"
                                        @change="handelCheckboxClosecode($event,item.code)"
                                    ></el-checkbox>
                                </el-col>
                            </el-checkbox-group>
                        </el-row>
                    </div>

                    <div style="margin-top:30px;" class="text_center">
                        <el-button type="primary" size="small" @click="step2SubmitSuccess">挽留成功</el-button>
                        <el-button type="primary" size="small" @click="step2SubmitFail">挽留失败</el-button>
                    </div>
                </div>
                <div v-show="step3Page" v-loading="pageLoading">
                    <el-form ref="formData" :model="formData" :rules="rules" label-width="150px">
                        <el-row>
                            <el-col :span="11" :offset="1">
                                <el-form-item label="账面余额：" class="text_fl">
                                    <span
                                        class="el-form-item-span"
                                    >{{pageFormValue.bookBalanceflag }}{{pageFormValue.bookBalance }}</span>
                                </el-form-item>
                            </el-col>
                            <el-col :span="11">
                                <el-form-item label="积分值：" class="text_fl">
                                    <span class="el-form-item-span">{{pageFormValue.integralValue }}</span>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="11" :offset="1">
                                <el-form-item label="电子现金余额：" class="text_fl">
                                    <span class="el-form-item-span">{{pageFormValue.ecashBalance }}</span>
                                </el-form-item>
                            </el-col>

                            <el-col :span="11">
                                <el-form-item label="是否绑定ETC：" class="text_fl">
                                    <span class="el-form-item-span"></span>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <!-- 话术 -->
                        <div class="hstable_wrap" v-if="speechList.length!=0">
                            <el-table
                                :data="speechList"
                                border
                                stripe
                                header-row-class-name="headerRow"
                                ref="showListTable"
                                class="heard-bg business_table hstable"
                                @selection-change="handleSelectionChange"
                            >
                                <el-table-column type="selection" label=" " min-width="55"></el-table-column>
                                <el-table-column label="业务话术">
                                    <template slot-scope="scope">{{scope.row.content}}</template>
                                </el-table-column>
                            </el-table>
                        </div>
                        <div style="margin-bottom:10px;" class="text_center">
                            <el-button type="primary" size="small" @click="handelSure">销户确认</el-button>
                        </div>
                    </el-form>
                    <el-dialog
                        v-drag
                        title="销户申请"
                        :visible.sync="centerDialogVisible"
                        width="400px"
                        :append-to-body="true"
                        top="30vh"
                        :close-on-click-modal="false"
                        center
                    >
                        <p>
                            账户类别：
                            <span>{{this.searchForm.accttypeStr}}</span>
                        </p>
                        <p v-if="this.pageFormValue.integralValue!==0">
                            积分值：
                            <span>{{this.pageFormValue.integralValue}}</span>
                        </p>
                        <p v-if="this.pageFormValue.ecashBalance!=='0'">
                            电子现金余额：
                            <span>{{this.pageFormValue.ecashBalance}}</span>
                        </p>
                        <!-- <p v-if="this.pageFormValue.isBindingETC==='1'">
                            是否绑定ETC：
                            <span>{{this.pageFormValue.isBindingETC}}</span>
                        </p>-->
                        <p v-if="this.pageFormValue.bookBalance!==0">
                            账面余额：
                            <span>{{this.pageFormValue.bookBalanceflag }}{{this.pageFormValue.bookBalance }}</span>
                        </p>
                        <p class="text_center padding_top15">
                            <span style="color:#3a8ee6; ">销户申请一经确认不得撤销，是否确认办理？</span>
                        </p>
                        <span slot="footer" class="dialog-footer">
                            <el-button
                                size="small"
                                icon="el-icon-circle-close"
                                @click="centerDialogVisible = false"
                            >取 消</el-button>
                            <el-button
                                type="primary"
                                size="small"
                                @click="submitForm"
                                icon="el-icon-circle-check"
                                v-preventReClick
                            >确定</el-button>
                        </span>
                    </el-dialog>
                </div>
            </div>
        </el-card>
    </div>
</template>

<script>
import { mapGetters } from 'vuex';
import moment from 'moment';
import {
    trimString,
    closePage,
    getDictMappingValue,
    itoStr,
    updateDeal3004,
    updateDeal3601,
    setETCCardInfo,
    getNewCardAccount3001,
    updateCardAccount3001,
} from '@/utils/Common';
import { isEmptyObject } from '@/utils/Object';

export default {
    name: 'CancelAccouunt',
    data() {
        return {
            formData: {
                CATEGORY: '', // 账户类别
                CARDNO: '', // 卡号
                IDTYPE: '', // //证件种类
                CUSTID: '', // 证件号码
                AUTOFLAG: '0', // 溢缴款自动结清申请
                CLSFLAG: '1', // 销户标志
                BANKFLAG: '0', // 销户自动结清转账行标志
                executionDate: '2021-06-20',
                closeReason: [], // 销户原因选中选项
                closeReasonIds: [], // 销户原因选中选项Ids
            },
            rules: {
                BEGDATE: [{ required: true, message: '请选择菜单类型' }],
            },
            // defaultParams: this.$store.getters.defaultParams || '', // 更新报文
            cancelAccouuntInfo: {}, // 销卡成功返回回来的数据
            isCATEGORY: '',
            centerDialogVisible: false,
            PRODUCT_value: '',
            productId: '',
            step1Page: true,//1-初审
            ifauditpass: false,//初审不通过显示
            step2Page: false,//2-挽留
            step3Page: false,//3-确认
            searchForm: { // 账户类型、卡号双选字段
                accttype: '', //账户类型，编号
                cardno: '', //账号
                accttypeStr: '', // 账户类型显示值
            },
            cardList: [], //卡列表
            closeReasonList: [], // 查询全部-销卡原因列表
            speechCraftList: [], //话术列表
            pageFormValue: { //页面表单值，随账户选择变动
                bookBalance: '', // 当前账面余额 3001-40
                bookBalanceflag: '',// 当前账面余额符号 3001-41
                ifbalancepass: '',
                authNoClaim: '', // 授权未请款金额 3001-16
                uncollectedPenalty: '', // 应收未收违约金 3001-84
                isHaveInstallment: '', // 是否有未结清分期   -  卡级别-获取3077遍历
                isMakeCardDay: '', // 是否为制卡日  -  卡级别-获取制卡日判断
                isBindingETC: '', // 是否绑定ETC  -  卡级别-接口获取
                ecashBalance: '0', // 电子现金余额  -   卡级别-获取-3096
                integralValue: '', // 积分值 3001-102
                unpassreason: '',//初审不通过原因
            },
            accountCardList: [], //账户下卡（是否绑定ETC，电子现金余额）列表
            pageAccountInfo: {}, // 下拉选变更，账户信息（废弃），改为newCardAccountInfo_3001
            RtnindFlag: '',//3077-翻页标志
            NEXTDAY_3077: '20000101',//3077-翻页交易日期
            NEXTMPNO_3077: '0',//3077-翻页分期付款序号
            InstallmentInfo_3077: [],//3077分期付款交易明细查询
            RTNIND_value: '', // 3134翻页标志
            ETCSTATUS_value: false,//3134ETC签约关系查询交易接口
            pageLoading: false, // 页面loading
            newCardAccountInfo_3001: '',//3001new-卡账户信息 每次切换账户更换信息
            step1SubmitCheck: true,//初审检验是否通过，金额类字段只要有金额＞0或者是否类字段结果为“是”的，只要满足其一，初审则不通过
            result3077: {},
            result3046: {},
            result3134: {},
            result3096: {},
            speechList: [],//话术列表
            selectedList: [],
            integralSummaryObj: {},
            MenuId: '',
            precardstat: '',//销户前状态
            ETCCard: '',//绑定ETC的卡号
        };
    },
    computed: {
        ...mapGetters([
            'defaultParams',
            'cardAccountInfo_3001',
            'cardList_3601',
            'cardInfo_3004',
            'pinFlag',
            'AccountionTYPE_INFO',
            'userInfo',
            'isCurrentMenuInfo',
            'checAllData',
        ]),
    },
    async mounted() {
        this.MenuId = this.$route.params.id || '';

        this.precardstat = this.cardInfo_3004.CARDSTAT.trim() === '' ? '空' : this.cardInfo_3004.CARDSTAT.trim();
        // let accountStat = this.cardAccountInfo_3001.CARDSTAT.trim();
        // let accountstatdesc = await getDictMappingValue('CLOCD', accountStat, this);
        this.pageValidation();
        this.newCardAccountInfo_3001 = this.cardAccountInfo_3001;
        this.formData.CATEGORY = this.cardInfo_3004.CATEGORY;
        this.formData.CARDNO = this.cardInfo_3004.CARDNO;
        this.formData.IDTYPE = this.cardInfo_3004.KEYTYPE;
        this.formData.CUSTID = this.cardInfo_3004.CUSTID;

        console.info(this.AccountionTYPE_INFO, "AccountionTYPE_INFO");
        await this.getDictValue();
        // 初始化双选下拉
        this.searchForm.accttype = this.cardInfo_3004.CATEGORY + '';
        this.searchForm.cardno = this.cardInfo_3004.CARDNO;
        await this.init();

    },
    methods: {
        async init() {
            console.info("newCardAccountInfo_3001", this.newCardAccountInfo_3001);
            await this.changeCardList(this.cardInfo_3004.CATEGORY);
        },
        pageValidation() {
            let accountStat = this.cardAccountInfo_3001.CARDSTAT.trim();
            // if (accountStat == "W" || accountStat == "WQ" || accountStat == "X1") {
            //     this.step1Page = false;
            //     this.$alert(
            //         "当前账户状态异常，账户状态：" + accountstatdesc + "，无法进入销户页面！",
            //         '销户提示',
            //         { customClass: 'warning', type: 'warning', showClose: false },
            //     ).then(() => {
            //         closePage(this.$route, this, 1);
            //     });
            // };
            // 1、增加账户状态为呆账核销、核销清户、停计息费(次优) 、停计息费(次优代偿) 、冻结账户时，页面校验提醒的逻辑。
            // （1）呆账核销 W ：“账户状态为呆账核销，查询无欠款后下工单处理‘
            // （2）核销清户 WQ：”账户状态为核销清户，无需再次处理销户“
            // （3）停计息费(次优) X1 、停计息费(次优代偿)X2 ：“账户状态为 ****，请出工单核实是否可以销户”；
            // （4）冻结账户 D：“账户状态为冻结账户，请客户联系司法机关“
            if (accountStat === "W") {
                this.$alert('账户状态为呆账核销，查询无欠款后下工单处理!', '销户申请提示', {
                    customClass: 'error', type: 'error',
                });
            }
            if (accountStat === "WQ") {
                this.$alert('账户状态为核销清户，无需再次处理销户!', '销户申请提示', {
                    customClass: 'error', type: 'error',
                });
            }
            if (accountStat === "X1") {
                this.$alert('账户状态为:停计息费(次优)，请出工单核实是否可以销户', '销户申请提示', {
                    customClass: 'error', type: 'error',
                });
            }
            if (accountStat === "X2") {
                this.$alert('账户状态为:停计息费(次优代偿)，请出工单核实是否可以销户', '销户申请提示', {
                    customClass: 'error', type: 'error',
                });
            }
            if (accountStat === "D") {
                this.$alert('账户状态为冻结账户，请客户联系司法机关', '销户申请提示', {
                    customClass: 'error', type: 'error',
                });
            }
        },
        // 账号选择变更事件
        async changeCardList(val) {
            console.log("============changeCardList-val：" + val);
            // 更新账户类型显示值
            this.searchForm.accttypeStr = await getDictMappingValue('CATE', val, this);

            let hasDefault = false; //是否包含默认卡
            this.cardList = [];
            for (let index = 0; index < this.cardList_3601.length; index++) {
                const cardTemp = this.cardList_3601[index];
                if (cardTemp.CATEGORY === val) {
                    this.cardList.push(cardTemp);
                    if (cardTemp.CARDNBR === this.cardInfo_3004.CARDNO) {
                        hasDefault = true;
                    }
                }
            }

            // 包含默认卡，卡号显示默认卡，不包含，显示cardList里第一张卡号
            if (hasDefault) {
                this.searchForm.cardno = this.cardInfo_3004.CARDNO;
            } else {
                this.searchForm.cardno = this.cardList[0].CARDNBR;
            }

            // 初始化页面元素值
            await this.changePageFormValue();
        },
        async get3077() {
            const appBody = {
                CARDNBR: this.searchForm.cardno, // 证件号码
                MPTYPE: '',
                OPERCODE: '1',
                OPT: '1',
                PINFLAG: '0', //验密标识
                PIN: '',// 密码
            };
            const defaultParams = JSON.parse(JSON.stringify(this.defaultParams));
            defaultParams.body.appHead.tranCode = '3077';
            defaultParams.body.appBody = appBody;
            // 3077交易

            await this.$post.common.transPort(defaultParams).then((res) => {
                if (res.status === 200) {
                    this.result3077 = JSON.parse(res.data.jsonRes);
                    console.log("result3077:", this.result3077);
                }
            });
        },
        async get3046() {
            const appBody_3046 = {
                OPT: 1, // 查询方式 1-用卡号查询 2-用证件号码查询
                CARDNBR: this.searchForm.cardno, // 卡号
                MPTYPE: '', // 分期类型,y-账单分期
                STATUS: '30', // 分期申请状态,30-待请款
                PINFLAG: '0', // 是否检查密码标志 0-不检查
                RTNIND: '', // 翻页标志 首次传空， 翻页传1
                APPREF: '', // 分期申请编号，首次查询时送空， 下翻页查询时上送上次查询结果的最后一条记录返回的分期付款申请编号
            };
            const defaultParams_3046 = JSON.parse(JSON.stringify(this.defaultParams));
            defaultParams_3046.body.appHead.tranCode = '3046';
            defaultParams_3046.body.appBody = appBody_3046;
            await this.$post.common.transPort(defaultParams_3046).then((res) => {
                if (res.status === 200) {
                    this.result3046 = JSON.parse(res.data.jsonRes);
                    console.log("this.result3046:", this.result3046);
                }
            });
        },
        async get6901() {
            const appBody = {
                CARDNBR: this.searchForm.cardno, // 卡号
                PINFLAG: '0', // 是否检查密码标志
                PIN: '', // 密码
                INQOPT: 1, // 查询方式 （1按卡号查询 2按证件号查询）
                LEVEL: 1, // 查询级别 1、客户级 2、卡账户级 3、卡片级 （查询方式为1时，支持123，查询方式为2时只支持1）
                BEGDAY: '', // 起始日期
                ENDDAY: '', // 终止日期
                NEXTDAY: '',
                NEXTMPNO: 0,
            };
            this.defaultParams.sysHead.busiName = '积分汇总查询';
            const defaultParams = JSON.parse(JSON.stringify(this.defaultParams));
            defaultParams.body.appHead.tranCode = '6901';
            defaultParams.body.appBody = appBody;
            await this.$post.common.transPort(defaultParams).then((res) => {

                this.pageLoading = false;
                if (res.status === 200) {
                    this.isShowTotal = true;
                    this.isShowView = true;
                    const result = JSON.parse(res.data.jsonRes);
                    console.log("总积分查询结果：", result);
                    if (result.sysHead.rspCd === '000000') {
                        this.integralSummaryObj = result.body.appBody;
                        this.pageFormValue.integralValue = this.integralSummaryObj.PointTotal;
                    }
                }

            });
        },

        // // 账户类型 字典取值
        async getDictValue() {
            this.isCATEGORY = await getDictMappingValue('CATE', this.formData.CATEGORY, this);
            this.PRODUCT_value = await getDictMappingValue('PRODUCT', this.cardInfo_3004.PRODUCT, this);
            this.closeReasonList = await this.getDictDetails('XH_REASON'); // 查询销户原因列表
            await this.getspeechList();
        },
        //根据菜单id查询话术列表
        async getspeechList() {
            console.log("this.isCurrentMenuInfo.id", this.isCurrentMenuInfo.id);
            var checkParam = {
                'id': this.MenuId || this.isCurrentMenuInfo.id,
            };
            this.$post.busiMenu.getlistByMenuId(checkParam).then((res) => {
                console.log("话术查询结果：", res);
                if (res.status === 200) { // http通讯成功
                    if (res.data.status == 0) { // 业务请求成功
                        this.speechList = res.data.content;
                    }
                }
            });
        },
        handleSelectionChange(val) {
            this.selectedList = val;
        },
        // //账户类型变动，页面值变化
        async changePageFormValue() {
            // this.step1SubmitCheck = true; // 初审是否通过判断,初始化成功
            // 更新 newCardAccountInfo_3001
            await getNewCardAccount3001(this.searchForm.cardno, this);
            console.info("hangePageFormValue-账户级别-this.newCardAccountInfo_3001", this.newCardAccountInfo_3001);
            this.pageFormValue.ifbalancepass = '';
            // 当前账面余额
            this.pageFormValue.bookBalance = this.newCardAccountInfo_3001.BALNCE;
            //账面余额符号
            this.pageFormValue.bookBalanceflag = this.newCardAccountInfo_3001.BALNCEFLG === '+' ? '' : this.newCardAccountInfo_3001.BALNCEFLG;
            if (this.newCardAccountInfo_3001.BALNCEFLG === '+' && parseFloat(this.newCardAccountInfo_3001.BALNCE) > 0) {
                this.pageFormValue.ifbalancepass = '0';
            }
            // 授权未请款金额
            this.pageFormValue.authNoClaim = this.newCardAccountInfo_3001.AUTHAMT;
            // 应收未收违约金
            this.pageFormValue.uncollectedPenalty = this.newCardAccountInfo_3001.PENCHG;


            //是否有未结清分期
            await this.get3077();
            await this.get3046();

            if ((this.result3077.sysHead.rspCd === '000000' && this.result3077.body.appBody.dataList.length > 0) || (this.result3046.sysHead.rspCd === '000000' && this.result3046.body.appBody.dataList.length > 0)) {
                this.pageFormValue.isHaveInstallment = '1';
            }
            //是否有制卡日当日
            console.log("this.cardList1", this.cardList);
            let todayStr = moment(new Date()).format('YYYYMMDD');
            for (let index = 0; index < this.cardList.length; index++) {
                const cardTemp = this.cardList[index];
                if (((cardTemp.OPENDATE + '').trim()) === todayStr) {
                    this.pageFormValue.isMakeCardDay = '1';
                    break;
                }
            }

            this.step1Check();
        },

        // //
        handelSure() {
            console.log("this.selectedList.length", this.selectedList.length);
            if (this.selectedList.length != this.speechList.length) {
                this.$alert('话术尚未全部勾选！', '提示', {
                    customClass: 'warning', type: 'warning',
                });
                return;
            }
            this.centerDialogVisible = true;
        },
        // 4011信用卡销户 销卡交易
        submitForm() {
            const defaultParam = JSON.parse(JSON.stringify(this.defaultParams));
            defaultParam.body.appHead.tranCode = '4011';// 修改交易号
            defaultParam.body.appBody = {
                PINFLAG: this.pinFlag,
                PIN: '',
                CARDNBR: this.formData.CARDNO,
                IDTYPE: this.formData.IDTYPE,// 证件种类
                CUSTID: this.formData.CUSTID,// 证件号码，
                CLSFLAG: this.formData.CLSFLAG,// //销户标志
                AUTOFLAG: this.formData.AUTOFLAG, // //溢缴款自动结清申请
                CLSFLAG: this.formData.CLSFLAG, // 销户标志
                BANKFLAG: this.formData.BANKFLAG, // 销户自动结清转账行标志
            };
            this.$post.common.transPort(defaultParam).then((res) => {
                console.log(res);
                if (res.status === 200) { // 请求成功
                    const cardlossofs = JSON.parse(res.data.jsonRes);
                    console.log(cardlossofs, '4011信用卡销户');
                    if (cardlossofs.sysHead.rspCd == '000000') { // 交易成功
                        this.cancelAccouuntInfo = cardlossofs.body.appBody;
                        this.updateCheckData(this.precardstat, 'Q');
                        // this.isShowSuccess=true;
                        updateCardAccount3001(this.cardInfo_3004.CARDNO, this);
                        updateDeal3004(this.cardInfo_3004.CARDNO, this);
                        updateDeal3601(this.cardInfo_3004.CARDNO, this.cardInfo_3004.KEYTYPE, this.cardInfo_3004.CUSTID, this);
                        const successMessage = `销户申请业务办理成功！`;

                        this.$alert(successMessage, '销户申请提示', {
                            customClass: 'success', type: 'success',
                            callback: (action) => {
                                this.handleClose();
                            },
                        });
                    } else {
                        const ErrorMessage = `错误码：${cardlossofs.sysHead.rspCd} ` + `错误信息：${cardlossofs.sysHead.rspMsg}`;
                        this.$alert(ErrorMessage, '销户申请', {
                            customClass: 'error', type: 'error',
                        });
                    }
                    this.centerDialogVisible = false;
                }
            });
        },

        updateCheckData(precardstat, nowcardstat) {
            const checAllDataItem = JSON.parse(JSON.stringify(this.checAllData));
            precardstat = precardstat.trim() === '' ? '空' : precardstat.trim();
            nowcardstat = nowcardstat.trim() === '' ? '空' : nowcardstat.trim();
            checAllDataItem[precardstat].falg = false;
            checAllDataItem[nowcardstat].falg = true;
            // 修改验证开关 结束后再 保存一下 checAllDataItem
            // console.log(`这里是 修改验证开关：名称为：${checAllDataItem.check_reserve_mobile.label}值为：${checAllDataItem.check_reserve_mobile.falg}：大对象为`,checAllDataItem);
            this.$store.commit('common/SAVE_CHECK_DATA', checAllDataItem);
        },
        // 关闭页面
        handleClose() {
            closePage(this.$route, this, 1);
        },
        // 跳转到销户申请初审页面
        pageJump() {
            this.$router.push({
                path: '/operationDeals/ClosingAccountFirstInstance',
            });
        },

        // 查字典-取销户原因列表
        async getDictDetails(val) {
            let params = {};
            let accountName;
            params = {
                dictValue: val,
                pageNum: 1,
                pageSize: 1000,
            };
            await this.$post.common.getBaseDataList(params).then((res) => {
                console.log(res, '=============getDictDetails-res，val:' + val);
                if (res.status === 200) {
                    accountName = res.data.content;
                } else {
                    this.$message.error(res.data.msg);
                }
            });
            return accountName;
        },
        // 销卡原因选中事件
        handelCheckboxClosecode(event, code) {
            if (event) {
                this.formData.closeReasonIds.push(code);
            } else {
                this.formData.closeReasonIds.forEach((item, i) => {
                    if (item === code) {
                        this.formData.closeReasonIds.splice(i, 1);
                    }
                });
            }
        },

        // 初审判断
        step1Check() {
            this.pageFormValue.unpassreason = '';
            //金额类字段只要有金额＞0或者是否类字段结果为“是”的，只要满足其一，初审则不通过，并显示原因；初审通过则进入销户挽留页面
            if (this.pageFormValue.bookBalanceflag != '-' && parseFloat(this.pageFormValue.bookBalance) > 0) {
                this.ifauditpass = true;
                this.pageFormValue.unpassreason = this.pageFormValue.unpassreason + '账面余额大于0,';
            }
            if (parseFloat(this.pageFormValue.uncollectedPenalty) > 0) {
                this.ifauditpass = true;
                this.pageFormValue.unpassreason = this.pageFormValue.unpassreason + '应收未收违约金不为0,';
            }
            if (parseFloat(this.pageFormValue.authNoClaim) > 0) {
                this.ifauditpass = true;
                this.pageFormValue.unpassreason = this.pageFormValue.unpassreason + '授权未请款金额不为0,';
            }
            if (this.pageFormValue.isHaveInstallment === '1') {
                this.ifauditpass = true;
                this.pageFormValue.unpassreason = this.pageFormValue.unpassreason + '有未结清分期,';
            }
            if (this.pageFormValue.isMakeCardDay === '1') {
                this.ifauditpass = true;
                this.pageFormValue.unpassreason = this.pageFormValue.unpassreason + '制卡日当日,';
            }
            if (this.ifauditpass) {
                this.pageFormValue.unpassreason = this.pageFormValue.unpassreason + '初审不通过！';
            }
        },

        // 初审提交
        async step1Submit() {
            if (!this.ifauditpass) {
                this.step1Page = false;
                this.step2Page = true;
                await this.initCloseData();
            } else {
                this.$alert('销户初审不通过！', '销户初审', {
                    customClass: 'warning', type: 'warning',
                });
                return;
            }
        },

        async initCloseData() {
            console.log("进入销户挽留页面：判断卡状态是否异常：逾期停卡、账户止付、卡片到期未续卡，账户额度为0,卡片丢失，未收到卡片，满足其一，直接到销户确认，不需要经过挽留页面", this.cardList);
            // 1、账户状态异常；2、账户额度为0；3、账户下所有卡均为挂失状态；

            let ifneedWL = '1';//是否需要挽留，1-需要，0-不需要
            let accountStat = this.cardAccountInfo_3001.CARDSTAT.trim();//账户状态

            //判断卡片状态是否异常
            // for (let index = 0; index < this.cardList.length; index++) {
            //     const cardTemp = this.cardList[index];
            //     if (((cardTemp.CARDSTAT + '').trim()) === 'O' || ((cardTemp.CARDSTAT + '').trim()) === 'H' || ((cardTemp.CARDSTAT + '').trim()) === 'NX' ||
            //         ((cardTemp.CARDSTAT + '').trim()) === 'L' || ((cardTemp.CARDSTAT + '').trim()) === 'N') {

            //         ifneedWL = '0';
            //         break;
            //     }
            // }
            //判断账户下卡片状态是全部挂失
            for (let index = 0; index < this.cardList.length; index++) {
                const cardTemp = this.cardList[index];
                if (((cardTemp.CARDSTAT + '').trim()) !== 'L') {
                    ifneedWL = '1';
                    break;
                } else {
                    ifneedWL = '0';
                }
            }
            //账户额度是否为0
            if (parseFloat(this.newCardAccountInfo_3001.CREDITLIMIT) === 0) {
                ifneedWL = '0';
            }
            //账户状态异常
            if (accountStat !== '') {
                ifneedWL = '0';
            }
            if (ifneedWL === '0') {//不需要挽留，直接跳转销户确认页面
                //销户记录入库
                this.closeAccountSaveDB('3', '无需挽留');
                this.step1Page = false;
                this.step2Page = false;
                this.step3Page = true;
                this.pageLoading = true;
                await this.initCloseData3();
                return;
            }
        },

        // 挽留-成功
        step2SubmitSuccess() {
            this.closeAccountSaveDB('1', '挽留成功');
            closePage(this.$route, this, 1);
        },
        // 挽留-失败
        async step2SubmitFail() {

            if (this.formData.closeReasonIds.length === 0) {
                this.$alert('请选择销户原因', '销户确认', {
                    customClass: 'warning', type: 'warning',
                });
                return;
            }

            //销户记录入库
            this.closeAccountSaveDB('2', '挽留失败');
            //切换确认页
            this.step2Page = false;
            this.step3Page = true;
            this.pageLoading = true;
            await this.initCloseData3();
        },

        //初始化销户确认页面数据
        async initCloseData3() {
            //积分值

            await this.get6901();

            //是否绑定etc
            //await this.get3134();
            //电子现金余额
            await this.get3096();

            this.pageLoading = false;
        },

        //循环查询账户下所有卡是否绑定etc
        // async get3134() {
        //     console.log("this.cardList3134", this.cardList);

        //     for (let i = 0; i < this.cardList.length; i++) {
        //         const appBody = {
        //             CARDNBR: this.cardList[i].CARDNBR, // 证件号码
        //             MPTYPE: '',
        //             INQSEL: '1',
        //             OPTION: '1',
        //             PINFLAG: '0', //验密标识
        //             PIN: '',// 密码
        //         };
        //         const defaultParams = JSON.parse(JSON.stringify(this.defaultParams));
        //         defaultParams.body.appHead.tranCode = '3134';
        //         defaultParams.body.appBody = appBody;
        //         // 3134交易

        //         await this.$post.common.transPort(defaultParams).then((res) => {
        //             if (res.status === 200) {
        //                 this.result3134 = JSON.parse(res.data.jsonRes);

        //             }
        //         });

        //         console.log("result3134:", this.result3134);
        //         if (this.result3134.sysHead.rspCd === '000000' && this.result3134.body.appBody.dataList.length > 0) {
        //             this.pageFormValue.isBindingETC = '1';
        //             this.ETCCard = this.cardList[i].CARDNBR.trim().substring(this.cardList[i].CARDNBR.trim().length - 4, this.cardList[i].CARDNBR.trim().length);
        //             break;
        //         } else {
        //             this.pageFormValue.isBindingETC = '';

        //         }
        //     }
        // },
        //查询电子现金余额
        async get3096() {
            console.log("this.cardList3096", this.cardList);
            for (let i = 0; i < this.cardList.length; i++) {
                const appBody = {
                    CARDNBR: this.cardList[i].CARDNBR, // 证件号码
                    STDATE: '20000101',
                    ENDDTE: moment(new Date()).format('YYYYMMDD'),
                    OPTION: 'A',
                    TRANTYPE: 'A',
                    PINFLAG: '0', //验密标识
                    PIN: '',// 密码
                };
                const defaultParams = JSON.parse(JSON.stringify(this.defaultParams));
                defaultParams.body.appHead.tranCode = '3096';
                defaultParams.body.appBody = appBody;
                // 3096交易

                await this.$post.common.transPort(defaultParams).then((res) => {
                    if (res.status === 200) {
                        this.result3096 = JSON.parse(res.data.jsonRes);

                    }
                });

                console.log("result3096:", this.result3096);
                //if (this.result3096.sysHead.rspCd === '000000') {
                this.pageFormValue.ecashBalance = parseFloat(this.pageFormValue.ecashBalance) + parseFloat(this.result3096.body.appBody.BALANCE);
                console.log("this.pageFormValue.ecashBalance:", this.pageFormValue.ecashBalance);
                //}
            }
        },
        // 销户记录入库
        closeAccountSaveDB(wlflag, wlreason) {
            // 拼接获取销户原因
            let closecodestr = ',';	// 销卡原因：代码1-原因描述1,代码2-原因描述2...
            const closecodeVal = this.formData.closeReason;
            const closecodeIdVal = this.formData.closeReasonIds;
            for (let i = 0; i < closecodeVal.length; i++) {
                closecodestr = `${closecodestr + closecodeVal[i]}-${closecodeIdVal[i]},`;
            }
            console.log('===========closeAccountSaveDB销户原因：', closecodestr);
            console.log('===========closeAccountSaveDB-this.userInfo', this.userInfo);

            // 参数：cardNo-卡号，opt-操作人，closeReason-销户原因
            var checkParam = {
                'wlFlag': wlflag,//挽留标志，1-成功，2-失败，3-不符合条件
                'wlReason': wlreason,//挽留原因
                'cardNo': this.searchForm.cardno,
                'xhFlag': '1', //是否可销户标志，1-是；0-否
                'closeReason': closecodestr, //销户原因
                'createUser': this.userInfo.userAccount,
                'busiType': '1', //业务类型，1-销户，2-销卡
            };

            this.$post.queryServiceClass.closeAcctRecord(checkParam).then((res) => {
                // console.log(res);
                // if (res.status === 200) { // http通讯成功
                //     if (res.data.status === 0) { // 业务请求成功
                //         const successMessage = `卡号${this.searchForm.cardno} 销户记录保存成功！`;
                //         const ts = '销户记录保存提示';
                //         this.$alert(successMessage, ts, {
                //             customClass: 'success', type: 'success',
                //         });
                //     } else {
                //         const ErrorMessage = `错误码：${res.data.status} ` + `错误信息：${res.data.msg}`;
                //         this.$alert(ErrorMessage, '销户记录保存失败', {
                //             customClass: 'error', type: 'error',
                //         });
                //     }
                // }
            });
        },

    },
};
</script>

<style lang='scss' >
.cancelAccouunt {
    .el-card__header {
        padding: 8px !important;
    }

    .el-card.is-always-shadow {
        -webkit-box-shadow: none;
        box-shadow: none;
    }
    .el-card {
        border: none;
    }
}
</style>
